/**
 * @version 1.0
 * @created 06 December 2010
 *
 * CancelBidsController
 *
 * Copyright @ 2010 by CES
 * All Rights Reserved.
 * CES CONFIDENTIAL AND TRADE SECRET
 * 
 */
package com.ces.knacky.controller.tools;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

import com.ces.knacky.framework.controller.ListController;
import com.ces.knacky.model.Bid;
import com.ces.knacky.model.UserTable;
import com.ces.knacky.services.AuctionService;

/**
 * This controller handles cancellation of the selected bids.
 * @author shivangi_walvekar
 *
 */
@Controller
public class CancelBidsController extends ListController<Bid>{
	/**
	 * Comma separated list of bid workflow audit ids selected from the JSP page.
	 */
	private String selectedIds;
	
	@Autowired
	private AuctionService auctionService;
	
	/**
	 * This method cancels the placed bids.
	 *
	 * @param 	request
	 * 			Request object to fetch session object.
	 * @return	String
	 * 			Represents View Resolver to be mapped in spring_views.xml file to return the list of
	 * 			bids for the logged-in user.
	 */
	@RequestMapping("/cancelPlacedBids.htm")
	public String execute(HttpServletRequest request) {
		auctionService.cancelBids(selectedIds);
		UserTable user = (UserTable) commonService.findFirstByDescription(UserTable.class,
		SecurityContextHolder.getContext().getAuthentication().getName());
		listEntity = auctionService.loadMyBids(user.getId());		
		return "listMyBids";
	}
	
	/**
	 * This method is used to return comma separated list of Item ids selected by the user.
	 *
	 * @return 	String
	 * 			Represents comma separated list of Item ids selected by the user.
	 */
	public String getSelectedIds() {
		return selectedIds;
	}

	/**
	 * It is used to set/map the ids selected by the user.
	 *
	 * @param 	selectedIds
	 * 			Represents comma separated list of Item ids selected by the user.
	 */
	@ModelAttribute("selectedIds")
	public void setSelectedIds(String selectedIds) {
		this.selectedIds = selectedIds;
	}
}
